package dao;

import pojo.Category;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class CategoryDao {
    //展现图书分类信息
    public static List<Category> getCategoryMsg() throws SQLException {
        List<Category> list=new ArrayList<>();
        String sql="select * from category";
        ResultSet rs = JDBCconection.getData(sql);
        Category category=null;
        while (rs.next()){
            category=new Category();
            category.setCid(rs.getString(1));
            category.setCname(rs.getString(2));
            category.setDesc(rs.getString(3));
            category.setSampleImg(rs.getString(4));
            list.add(category);
        }
        return list;
    }
    //修改图书分类信息
    public static Boolean updateCategory(Category category){
        String sql="update category set cname='"+category.getCname()+"',descript='"+category.getDesc()+"',sampleImg='"+category.getSampleImg()+"' where cid='"+category.getCid()+"'";
        if (JDBCconection.updata(sql)==true){
            return true;
        }else {
            return false;
        }
    }

    public static Boolean addCategory(Category category) {
        String sql="insert into category values('"+category.getCid()+"','"+category.getCname()+"','"+category.getDesc()+"','"+category.getSampleImg()+"')";
        if(JDBCconection.updata(sql)==true){
            return true;
        }else {
            return false;
        }
    }
}
